package wx.controls
{
	import flash.display.DisplayObject;
	
	import wx.core.Control;
	import wx.core.ITheme;
	import wx.core.SettingCache;
	import wx.layout.HorizontalLayout;

	
	/**
	 * 
	 * @author wujianqi
	 * 
	 * 顶部导航控件
	 * 
	 */	
	public class ActionBar extends Control
	{
		
		private var _barSkin:DisplayObject;
		private var _title:String;
		private var _leftItems:Vector.<DisplayObject>;
		private var _rightItems:Vector.<DisplayObject>;
		
		private var _left:HorizontalLayout;
		private var _right:HorizontalLayout;
		
		private var _label:Label;
		
		private const _theme:ITheme = SettingCache.theme;
		
		public function ActionBar($title:String = "")
		{
			super();
			_barSkin = _theme.actionBarSkin;
			validSkinItem(_barSkin);
			
			_title = $title;
			_barSkin.width = SettingCache.mainWidth;
			addChild(_barSkin);
			addLabel();
		}	
		
		private function addLabel():void {
			if(_label && contains(_label)) removeChild(_label);
			_label = new Label(_title,_theme.largeFontColor,_theme.largeFontSize);
			addChild(_label);			
			_label.x = (_barSkin.width - _label.width)/2;
			_label.y = (_barSkin.height - _label.height)/2;
		}
		

		public function get leftItems():Vector.<DisplayObject>
		{
			return _leftItems;
		}

		public function set leftItems(value:Vector.<DisplayObject>):void
		{
			if(_leftItems != value){
				_leftItems = value;
				updateLeft();
			}			
		}
		
		private function updateLeft():void {
			if(_left && contains(_left)) removeChild(_left);
			_left = new HorizontalLayout(2,_leftItems);
			_left.x = 5;
			addChild(_left);
			_left.y = (_barSkin.height - _left.height)/2;
		}
		
		public function get rightItems():Vector.<DisplayObject>
		{
			return _rightItems;
		}
		
		public function set rightItems(value:Vector.<DisplayObject>):void
		{
			if(_rightItems!= value){
				_rightItems = value;
				updateRight();
			}
		}
		
		private function updateRight():void {
			if(_right && contains(_right)) removeChild(_right);
			_right = new HorizontalLayout(2,_rightItems);			
			addChild(_right);
			_right.x = SettingCache.mainWidth - _right.width + 5;
			_right.y = (_barSkin.height - _right.height)/2;
		}
		
		override public function set width(value:Number):void{			
			super.width = value;
			addLabel();
			updateLeft();
			updateRight();
		}
		override public function set height(value:Number):void{			
			super.height = value;
			addLabel();
			updateLeft();
			updateRight();
		}

	}
}